package kr.hkit.androidcomplete01.ch06.work;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Bundle;
import android.view.View;

public class DrawPath extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new MyView(this));
		
	}
	
	class MyView extends View{

		private Paint paint;
		private Path path;
		
		public MyView(Context context) {
			super(context);
			paint = new Paint();
			path = new Path();
		}
		@Override
		protected void onDraw(Canvas canvas) {
			super.onDraw(canvas);
			
			canvas.drawColor(Color.LTGRAY);
			paint.setStrokeWidth(5);
			paint.setColor(Color.RED);
			paint.setStyle(Paint.Style.STROKE);
			
			//원, 사각형을 패스로 정의한 후 출력
			path.addCircle(50, 50, 40, Path.Direction.CW);
			path.addRect(100,10, 190, 90, Path.Direction.CW);
			canvas.drawPath(path, paint);
			
			//직선 곡선을 패스로 정의한 후 출력
			path.reset();
			path.moveTo(10,110);
			path.lineTo(50, 150);
			path.rLineTo(50, -30);
			path.quadTo(120, 170, 200, 110);
			paint.setStrokeWidth(3);
			paint.setColor(Color.BLUE);
			canvas.drawPath(path, paint);
			
			//곡선 패스 출력
			path.reset();
			path.moveTo(10,220);
			path.cubicTo(80, 150, 150, 220, 220, 180);
			paint.setStrokeWidth(2);
			paint.setColor(Color.BLACK);
			canvas.drawPath(path, paint);
			
			//곡선 패스 위에 텍스트 출력
			paint.setTextSize(20);
			paint.setStyle(Paint.Style.FILL);
			paint.setAntiAlias(true);
			canvas.drawTextOnPath("Cruved Text on Path", path, 0,0,paint);
		}
	}
}
